package leetcode.D100.T12;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: DYZ
 * @Create: 2021-08-08 22:21:02 星期日
 */

public class Solution {

    private static final int[] values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
    private static final String[] chars = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};

    public String intToRoman(int num) {
        StringBuilder sb = new StringBuilder();
        int curIdx = 0;
        while(num > 0) {
            while(num < values[curIdx]) {
                curIdx++;
            }
            num -= values[curIdx];
            sb.append(chars[curIdx]);
        }
        return sb.toString();
    }
}
